import express from "express"

import user from "./routes/user.js"

import news from "./routes/news.js"

const app = express()

// 处理JSON格式的参数
app.use(express.json())

// // 处理urlencoded参数
app.use(express.urlencoded({extended: false}))

app.use("/user", user)

app.use("/news", news)

// 错误中间件
app.use(function(arr, request, response, next) {
  console.log("出错了", arr.message);
  response.json({ code: -1, msg: arr.message })
})

export default app
